package cn.ject.mcpserver;

import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;

public class MyTestSse {

    @Test
    public void testSse() {

        var transport = new HttpClientSseClientTransport("http://localhost:8080");

        try (var client = McpClient.sync(transport).build()) {

            client.initialize();

//            McpSchema.ListToolsResult listToolsResult = client.listTools();

//            System.out.println(listToolsResult);

            McpSchema.CallToolResult callToolResult = client.callTool(new McpSchema.CallToolRequest("getWeather", Map.of("city", "北京")));


            List<McpSchema.Content> content = callToolResult.content();

            Assertions.assertNotNull(content);
            Assertions.assertEquals(content.size(), 1);

            McpSchema.TextContent content1 = (McpSchema.TextContent) content.get(0);

            System.out.println(content1.text());

        }

    }
}
